/*
 * Functions for MaVRec
 *
 */

function clearForms(){
  var type = null;
  for (var x=0; x<document.forms.length; x++){
    for (var y=0; y<document.forms[x].elements.length; y++){
      type = document.forms[x].elements[y].type;
      switch(type){
        case "text":
        case "textarea":
        case "password":
          document.forms[x].elements[y].value = "";
          break;
        case "radio":
        case "checkbox":
          document.forms[x].elements[y].checked = "";
          break;
        case "select-one":
          document.forms[x].elements[y].options[0].selected = true;
          break;
        case "select-multiple":
          for (z=0; z<document.forms[x].elements[y].options.length; z++){
            document.forms[x].elements[y].options[z].selected = false;
          }
        break;
      }
    }
  }
}

function selectAll(id) {
	setAll(id,true);
}

function selectNone(id) {
	setAll(id,false);
}

function setAll(id,value) {
	var root = document.getElementById(id);
	if (root) {
		var children = root.getElementsByTagName('*');
		if (children) {
			for (i=0; i< children.length; i++) {
				children[i].checked = value;
			}
		}
	} else {
		alert('element.id[' + id + '] not found!');
	}
	return;
}

function toggle(id) {
	var target = document.getElementById(id);
	if (target.style.display == "block") {
    	target.style.display = "none";
  	} else {
		target.style.display = "block";
	}
} 